package cn.hp.kyc;
import cn.hp.kyc.money.User;
import java.util.List;
import java.util.Scanner;

/**
 * @author yc
 * @year 2022年05月24日20:43
 */
public class GeneralUser {
    public void generalUser(boolean sign, int aa,List<User> list) {
        Scanner sc = new Scanner(System.in);
        while (sign) {
            System.out.println("*****************************************");
            System.out.println("********请输入你想要的操作类型：************");
            System.out.println("********1.余额查询        2.取款***********");
            System.out.println("********3.转账           4.存款***********");
            System.out.println("********5.退卡                  **********");
            System.out.println("******************************************");
            int operate1 = sc.nextInt();
            if (operate1 == 1) {
                System.out.println(list.get(aa).getBalance());
            }
            if (operate1 == 2) {
                System.out.println("请输入您想取款的数目");
                int operate2 = sc.nextInt();
                if (operate2 < list.get(aa).getBalance()) {
                    User stu = list.get(aa);
                    stu.setBalance(list.get(aa).getBalance() - operate2);
                    System.out.println(list.get(aa).getBalance());
                } else {
                    System.out.println("余额不足");
                }
            }
            if (operate1 == 3) {
                boolean sign1 = true;
                int a2 = 0;

                while (sign1) {
                    System.out.println("请输入对方的账户号码:");
                    String account6 = sc.nextLine();

                    for (int i = 0; i < list.size(); i++) {
                        if (account6.equals(list.get(i).getAccount())&&i!=aa) {
                            a2 = i;
                            sign1 = false;
                            break;
                        }
                        if(sign1&&i==list.size()-1){
                            System.out.println("对不起你输入的账号有误~~~");
                        }
                    }

                }
                System.out.println("请输入您想转账的数目");
                int operate3 = sc.nextInt();
                if (operate3 < list.get(aa).getBalance()) {
                    User stu = list.get(aa);
                    stu.setBalance(list.get(aa).getBalance() - operate3);
                    User stu1 = list.get(a2);
                    stu1.setBalance(list.get(a2).getBalance() + operate3);
                    System.out.println(list.get(aa).getBalance());
                } else {
                    System.out.println("余额不足");
                }
            }
            if (operate1 == 4) {
                System.out.println("请输入您想存款的数目");
                int operate2 = sc.nextInt();
                User stu = list.get(aa);
                stu.setBalance(list.get(aa).getBalance() + operate2);
                System.out.println(list.get(aa).getBalance());
            }
            if (operate1 == 5) {
                System.out.println("是否确认要退出");
                System.out.println("请输入Y/N");
                String a3 = sc.next();
                if (a3.equalsIgnoreCase("y")) {
                    sign = false;
                }
            }
        }
    }
}